package com.weilf.zookeeper.config;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;

import java.util.concurrent.CountDownLatch;

/**
 * 这个类是创建zookeeper 时的回调
 * @author weil-f
 * @date 2021/2/7 8:22
 */
public class DefaultWatcher implements Watcher {

	private CountDownLatch countDownLatch;

	public void setCountDownLatch(CountDownLatch countDownLatch) {
		this.countDownLatch = countDownLatch;
	}

	public void process(WatchedEvent watchedEvent) {
		switch (watchedEvent.getState()) {
			case Unknown:
				break;
			case Disconnected:
				break;
			case NoSyncConnected:
				break;
			case SyncConnected:
				// 连接成功后，这里需要将阻塞放行
				countDownLatch.countDown();
				break;
			case AuthFailed:
				break;
			case ConnectedReadOnly:
				break;
			case SaslAuthenticated:
				break;
			case Expired:
				break;
		}
	}
}
